#!/bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
#   ./repeat n operation vm_name optional_args
#

if [ $# -ne 2 ]; then 
   echo "usage: $0 n vm_name"
   exit 1
fi 
N=$1
VM=$2

MASTER=`xe pool-list params=master --minimal`
START=$(date +%s)

echo "# vm_number cumulative_time load_average"
perform () {
    i=$1
    VM_UUID=`xe vm-list name-label=${VM}${i} params=uuid --minimal`
    if [ "${VM_UUID}" != "" ]; then
	TMP=`xe vm-destroy uuid=${VM_UUID}`
    fi
    CURR=$(date +%s);
    DIFF=$(( ${CURR} - ${START} ));
    LOADAVG=`xe host-data-source-query data-source=loadavg host=${MASTER}`
    echo "${i} ${DIFF} ${LOADAVG}"; 
}

for i in `seq 1 ${N}`; do 
    perform $i;
done
